function e(e) {
    return function() {
        var r = e.apply(this, arguments);
        return new Promise(function(e, t) {
            function n(i, u) {
                try {
                    var a = r[i](u), o = a.value;
                } catch (e) {
                    return void t(e);
                }
                if (!a.done) return Promise.resolve(o).then(function(e) {
                    n("next", e);
                }, function(e) {
                    n("throw", e);
                });
                e(o);
            }
            return n("next");
        });
    };
}

function r(e) {
    return new Promise(function(r, t) {
        var n = {
            uri: e,
            headers: {
                "user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
            },
            followRedirect: !1,
            resolveWithFullResponse: !0
        };
        f.get(n, function(e, t, n) {
            r(t);
        });
    });
}

function t(e) {
    return new Promise(function(r) {
        return setTimeout(r, e);
    });
}

var n = function() {
    var t = e(regeneratorRuntime.mark(function e(t) {
        var n, i;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, r(t);

              case 2:
                if (n = e.sent, !(i = new RegExp("video/(.*?)/.*?mid=(.*?)&")).test(n.body)) {
                    e.next = 10;
                    break;
                }
                return item_id = RegExp.$1, mid = RegExp.$2, e.abrupt("return", {
                    item_id: item_id,
                    mid: mid
                });

              case 10:
                return e.abrupt("return", null);

              case 11:
              case "end":
                return e.stop();
            }
        }, e, this);
    }));
    return function(e) {
        return t.apply(this, arguments);
    };
}(), i = function() {
    var r = e(regeneratorRuntime.mark(function e(r, t) {
        var n, i, u;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return n = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + r, 
                e.prev = 1, i = {
                    uri: n,
                    headers: {
                        authority: "www.iesdouyin.com",
                        "user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
                        "content-type": "application/x-www-form-urlencoded",
                        accept: "*/*",
                        referer: "https://www.iesdouyin.com/share/video/" + r + "/?region=CN&mid=" + t + "&u_code=15b9142gf&titleType=title&utm_source=copy_link&utm_campaign=client_share&utm_medium=android&app=aweme",
                        "accept-language": "zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7"
                    }
                }, e.next = 5, p(i);

              case 5:
                return u = e.sent, e.abrupt("return", JSON.parse(u));

              case 9:
                e.prev = 9, e.t0 = e.catch(1), console.log(e.t0);

              case 12:
              case "end":
                return e.stop();
            }
        }, e, this, [ [ 1, 9 ] ]);
    }));
    return function(e, t) {
        return r.apply(this, arguments);
    };
}(), u = function() {
    var r = e(regeneratorRuntime.mark(function e(r) {
        var t, n, i;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return t = "https://api.oddfar.com/g/run/q.php?url=" + r, e.prev = 1, n = {
                    uri: t
                }, e.next = 5, p(n);

              case 5:
                return i = e.sent, e.abrupt("return", i);

              case 9:
                e.prev = 9, e.t0 = e.catch(1), console.log(e.t0);

              case 12:
              case "end":
                return e.stop();
            }
        }, e, this, [ [ 1, 9 ] ]);
    }));
    return function(e) {
        return r.apply(this, arguments);
    };
}(), a = function() {
    var r = e(regeneratorRuntime.mark(function e(r) {
        var n, i, u, a, s, c, p;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                if (!(n = r.item_list ? r.item_list[0].video.play_addr.url_list[0] : null)) {
                    e.next = 23;
                    break;
                }
                i = !1, u = 0, a = n.replace("playwm", "play"), s = r.item_list[0].video.origin_cover.url_list[0], 
                c = 1;

              case 7:
                if (!(c < 2)) {
                    e.next = 22;
                    break;
                }
                return u += 1, e.next = 11, o(a);

              case 11:
                if (-1 === (p = e.sent).search(/v\d+\-dy\.ixigua\.com/g)) {
                    e.next = 17;
                    break;
                }
                return i = !0, e.abrupt("break", 22);

              case 17:
                return e.next = 19, t(300);

              case 19:
                c++, e.next = 7;
                break;

              case 22:
                return e.abrupt("return", {
                    code: 1,
                    tryCount: u,
                    tested: i,
                    playAddress: p,
                    cover: s
                });

              case 23:
              case "end":
                return e.stop();
            }
        }, e, this);
    }));
    return function(e) {
        return r.apply(this, arguments);
    };
}(), o = function() {
    var t = e(regeneratorRuntime.mark(function e(t) {
        var n, i;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, r(t);

              case 2:
                if (n = e.sent, !(i = new RegExp('href="(.*?)"')).test(n.body)) {
                    e.next = 6;
                    break;
                }
                return e.abrupt("return", RegExp.$1);

              case 6:
              case "end":
                return e.stop();
            }
        }, e, this);
    }));
    return function(e) {
        return t.apply(this, arguments);
    };
}(), s = function() {
    var r = e(regeneratorRuntime.mark(function e(r) {
        var t, u, o;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, n(r);

              case 2:
                if (!(t = e.sent)) {
                    e.next = 13;
                    break;
                }
                return e.next = 6, i(t.item_id, t.mid);

              case 6:
                return u = e.sent, e.next = 9, a(u);

              case 9:
                return o = e.sent, e.abrupt("return", o);

              case 13:
                return e.abrupt("return", {
                    code: 0
                });

              case 14:
              case "end":
                return e.stop();
            }
        }, e, this);
    }));
    return function(e) {
        return r.apply(this, arguments);
    };
}(), c = require("wx-server-sdk"), p = require("request-promise"), f = require("request");

c.init("mike-52kvs"), exports.main = function() {
    var r = e(regeneratorRuntime.mark(function e(r, t) {
        var n;
        return regeneratorRuntime.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                if ("yes" != r.save) {
                    e.next = 7;
                    break;
                }
                return e.next = 3, u(r.url);

              case 3:
                return n = e.sent, e.abrupt("return", n);

              case 7:
                return e.abrupt("return", s(r.url));

              case 8:
              case "end":
                return e.stop();
            }
        }, e, void 0);
    }));
    return function(e, t) {
        return r.apply(this, arguments);
    };
}();